//
//  LYMainViewController.swift
//  Swift---新浪微博练习代码
//
//  Created by Mr.Yan on 2017/6/28.
//  Copyright © 2017年 Mr.Yan. All rights reserved.
//

import UIKit

class LYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

  addChildViewController(childController: LYHomeViewController(), title: "首页", imageName: "tabbar_home")
         addChildViewController(childController: LYMessageViewController(), title: "消息", imageName: "tabbar_message_center")
         addChildViewController(childController: LYDiscoverViewController(), title: "发现", imageName: "tabbar_discover")
         addChildViewController(childController: LYProfileViewController(), title: "我", imageName: "tabbar_profile")
    }

    
    func addChildViewController(childController: UIViewController, title:String, imageName:String) {
        
        
        //设置title  ([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)选中颜色的字体颜色
        childController.navigationItem.title = title
        childController.tabBarItem.title = title
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: UIControlState.selected)
        //设置image
        childController.tabBarItem.image = UIImage(named: imageName)
        //选中  withRenderingMode(UIImageRenderingMode.alwaysOriginal)  图片渲染方式
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
        
        //导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        //添加子控制器
        addChildViewController(nav)
    }
}
